package io.github.dgfwork.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Lookup;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * 通过实现接口的方式实现了自动注入，是由BeanPostProcessor实现的。
 */

//@Component
public class Person implements ApplicationContextAware {

	private ApplicationContext applicationContext;

	// 不能@Autowired
	private Cat cat;

	// 容器应该新创建一个
	@Lookup
	public Cat getCat() {
		return cat;
	}

	@Autowired
	public void setCat(Cat cat) {
		this.cat = cat;
	}

	// 回调机制
	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		this.applicationContext = applicationContext;
	}
}
